chdkfandomcom-20200222-history
CHDK-PT : A tool for porting CHDK to different firmware versions of the same camera
[ Modified from : new firmware version] Porting CHDK to a new camera for the first time is really hard and very time consuming. Porting to a different firwmare version of the same camera is much easier. With the introduction on CHDK-PT tool, it has become even easier. At least that's the hope. Prerequisites: *the CHDK-PT porting tool CHDK-PT (stub for now) *a working CHDK build environment like CHDK-Shell *a good text editor, preferrably with a built-in diff function like Notepad++ *a basic knowledge of software, although you will not really be writing code, just changing existing code to reflect difference between firmware version of the same camera. *from a working port of you camera, you will need the firmware dump (PRIMARY.BIN) file and the camera specificfiles (boot.c, capt_seq.c, lib.c, movie_rec.c etc) in platform//sub//* *for the new version you are trying to support, you will need the firmware dump (PRIMARY.BIN) Steps: *Create the platform//sub//* for your new canon firmware. *Copy the most closely related (i.e. numerically closest version) sub to a sub named for your new firmware. (e.g. 200h -> 201a) *Now you are ready to start updating files. I suggest keeping notes of which files you changed and what you did. *Build the new sub, with the PRIMARY.BIN in place. This will obviously not be a working port, you just want to generate stubs_entry.S *Diff the newly generated stubs_entry.S and the one for the already supported firmware - while many of the addresses will have changed, you are looking to see if the same stubs were found with the same percentage of success. *Use CHDK-PT Convert Stubs 'function to create a new stubs_entry_2.S file for your new port. *Use CHDK-PT '''Stubs File '''function tp dissassemble and create C file version of the stubs_entry_2.S files for the existing port and for your new port. Use the diff function in Notepad++ to compare the two resulting files. Where the routines match, your are done. If they don't match then you need to go searching for a better match with '''Local '''mode '<<>> *Open boot.c, find boot(), and compare the values there with the loops in the firmware dump. Update the code corresponding to the loops above. The start of initialized data has probably moved. If the sizes of the data and BSS have not changed, it's a good indication that the addresses of variables used by CHDK have not changed. *Now scan through the assembler in boot.c, and the corresponding code in IDA. You don't really have to really examine every line, you are mostly looking for calls to functions that have an address higher than highest unchanged address noted above. If you find one, compare it with what's in IDA, and update as needed. Also keep an eye out for variables that might have moved. *Follow the same procedure for the capt_seq.c and movie_rec.c *If one of the functions you have to update is has moved, you probably want to copy the assembler from scratch rather than trying to correct it. *lib.c: If no variables have moved, you probably don't have to do anything here. You can sanity check by searching for the constants in both dumps, and making sure they are referenced by identical code (use "search for a sequence of bytes"). Hardware addresses are unlikely to have changed. *stubs_min.S: pretty much the same as lib.c, except FlashParamsTable which will probably have moved by the same amount as the canon data. *stubs_entry_2.S: Scan through for addresses that are higher than highest unchanged address, and correct as needed. *makefile.inc: MEMISOSTART will need updating if the size of canon DATA + BSS has changed. *That's it, you are done. Build it (from scratch with clean !) and find someone to try it it out... *OK, you weren't actually quite done yet. Assuming it works, update the toplevel makefile to include your new sub, and commit or submit a patch. "Note that some of the assumptions above (like variables not moving) are just educated guesses. Canon could have changed the order of variables or functions but had them come out the same size."